﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.ComponentModel;

namespace TA.Turbo.Controls
{
	public class CheckBoxNode : BaseTextNode
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public CheckBoxNode()
		{
		}
		#endregion
		#region EVENTS
		#endregion
		#region PROPS
		[NotifyParentProperty(true)]
		[DefaultValue(false)]
		public bool Checked { get; set; }
		#endregion
		#region METHODS
		#endregion
		#endregion
		#region INTERNAL
		#region CONST/STATIC
		#endregion
		#region VARS
		#endregion
		#region PROPS
		protected override TreeNodeType Type
		{
			get { return TreeNodeType.CheckBox; }
		}
		#endregion
		#region METHODS
		#region INIT
		#endregion
		#region DATA
		public override void SerializeContents(TA.JSON.JsonWriter jw)
		{
			base.SerializeContents(jw);

			if (this.Checked)
			{
				jw.PropertyName("K");
				jw.Value(this.Checked);
			}
		}
		public override void DeserializeContent(TA.JSON.IJsonReader jr, string propShortName)
		{
			switch (propShortName)
			{
				case "K": this.Checked = (bool)jr.Value; break;
				default: base.DeserializeContent(jr, propShortName); break;
			}
		}
		#endregion
		#region HANDLERS
		#endregion
		#region RENDER
		protected override void RenderContentsMain(TreeView owner, TreeNodePosition position, int level, HtmlTextWriter writer)
		{
			if (!string.IsNullOrEmpty(this.ToolTip))
				writer.AddAttribute(HtmlTextWriterAttribute.Title, this.ToolTip);
			writer.RenderBeginTag(HtmlTextWriterTag.Label);

			writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox");
			if (this.Checked)
				writer.AddAttribute(HtmlTextWriterAttribute.Checked, "checked");
			//if (!string.IsNullOrEmpty(this.ToolTip))
			//  writer.AddAttribute(HtmlTextWriterAttribute.Title, this.ToolTip);
			writer.RenderBeginTag(HtmlTextWriterTag.Input);
			writer.RenderEndTag();

			writer.Write(" ");
			writer.Write(this.Text);
			
			writer.RenderEndTag();
		}
		#endregion
		#endregion
		#endregion
	}
}
